<template>
  <div id="container">
    <!--图表容器-->
    <div id="newCharts"></div>
  </div>
</template>

<script>
import * as echarts from "echarts";
export default {
  props: ["datas", "count"],
  data() {
    return {
      myChart: {},
    };
  },

  watch: {
    datas(newValue, oldValue) {
      if (this.myChart) {
        this.myChart.clear();
        this.myChart.setOption(this.options);
      }
    },
  },

  computed: {
    options() {
      const option = {
        title: {
          text: "密钥块",
          subtext: "计算分布",
          left: "center",
        },
        tooltip: {
          trigger: "item",
        },
        legend: {
          orient: "vertical",
          left: "left",
        },
        series: [
          {
            name: "Access From",
            type: "pie",
            radius: "50%",
            data: this.datas,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)",
              },
            },
          },
        ],
      };
      return option;
    },
  },

  mounted() {
    if (this.datas) {
      this.showChart();
    }
  },
  methods: {
    showChart() {
      var chartDom = document.getElementById("container newCharts");
      this.myChart = echarts.init(chartDom);
      this.options && this.myChart.setOption(this.options);
    },
  },
};
</script>

<style  scoped>
#container {
  width: 500px;
  height: 400px;
  padding-top: 100px;
  outline: 1px solid #eee;
}
#newCharts {
  margin: 0 auto;
  width: 100%;
  height: 100%;
}
</style>
